﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="~/Controls/TopToolbar.ascx.cs" Inherits="PointTracker.Controls.TopToolbar" %>

<script language="javascript" type="text/javascript">
    // Verifies that all the necessary fields for adding a class are filled in
    function VerifyFields() {
        //alert("test");

        error_message.style.color = "red";

        var userEmail = document.getElementById("<%= TextBoxUserEmail.ClientID %>").value;
        var userPassword = document.getElementById("<%= TextBoxPassword.ClientID %>").value;

        var validEmail = echeck(userEmail);
        var validPassword = userPassword != "";

        if (!validEmail) {
            error_message.innerHTML = 'Invalid user e-mail';
        }
        else if (!validPassword) {
            error_message.innerHTML = 'Please enter a password';
        }
        return validEmail && validPassword;
    }

    function echeck(str) {
        var at = "@"
        var dot = "."
        var lat = str.indexOf(at)
        var lstr = str.length
        var ldot = str.indexOf(dot)
        if (str.indexOf(at) == -1) {
            return false
        }

        if (str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr) {
            return false
        }

        if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr) {
            return false
        }

        if (str.indexOf(at, (lat + 1)) != -1) {
            return false
        }

        if (str.substring(lat - 1, lat) == dot || str.substring(lat + 1, lat + 2) == dot) {
            return false
        }

        if (str.indexOf(dot, (lat + 2)) == -1) {
            return false
        }
        if (str.indexOf(" ") != -1) {
            return false
        }

        return true
    }
</script>

<div id="header">
    <div id="logo">
        <img src="/images/point_tracker_logo.png" alt="Point Tracker" title="Point Tracker" />
    </div>
    <div id="header_right">
        User E-mail: <asp:TextBox ID="TextBoxUserEmail" runat="server"></asp:TextBox>
        Password: <asp:TextBox ID="TextBoxPassword" TextMode="Password" runat="server"></asp:TextBox>
        <asp:Button ID="ButtonLogin" OnClick="VerifyUser" OnClientClick="return VerifyFields();" runat="server" Text="Log in"/>
        <br />
        <span id="error_message"></span>
        <a href="/forgotPassword.aspx" id="forgot_pw">Forgot password?</a>       
    </div>
</div>
<div class="clear"></div>